
function renderGraph(graph, parent_container, width, height)
{

var color = d3.scale.category20();

if (graph === undefined) {
    graph = {
         nodes : [],
         links : [],
         labelAnchors : [],
         labelAnchorLinks : []
        };
    }

var force = d3.layout.force()
    .size([width, height])
    .nodes(graph.nodes)
    .links(graph.links)
    .gravity(0.1)
    .linkDistance(50)
    .charge(-1000);


var svg = d3.select("#"+parent_container).append("svg")
    .attr("width", width)
    .attr("height", height);

  force.start();

  var link = svg.selectAll(".link")
      .data(graph.links)
    .enter().append("line")
      .attr("class", "link")
      .style("stroke-width", function(d) { return Math.sqrt(d.value); });

  var node = svg.selectAll(".node")
      .data(graph.nodes)
    .enter().append("circle")
      .attr("class", "node")
      .attr("r", function(d) { return d.score; })
      .style("fill", function(d) { return color(d.group); })
      .call(force.drag);

  node.append("title")
      .text(function(d) { return d.label; });

  node.append("text")
      .attr("dx", 12)
      .attr("dy", ".35em")
      .text(function(d) { return "d.name"; });
            
//  node.append("image")
//      .attr("xlink:href", "https://github.com/favicon.ico")
//      .attr("x", -8)
//      .attr("y", -8)
//      .attr("width", 16)
//      .attr("height", 16);

  force.on("tick", function() {
    link.attr("x1", function(d) { return d.source.x; })
        .attr("y1", function(d) { return d.source.y; })
        .attr("x2", function(d) { return d.target.x; })
        .attr("y2", function(d) { return d.target.y; });

    node.attr("cx", function(d) { return d.x; })
        .attr("cy", function(d) { return d.y; });
  });
};
